package com.gtenacg.cartoonservice.controller;

import com.gtenacg.cartoonservice.common.annotation.CheckToken;
import com.gtenacg.cartoonservice.common.Result;
import com.gtenacg.cartoonservice.pojo.model.RelationCartoonAuthor;
import com.gtenacg.cartoonservice.service.RelationCartoonAuthorService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/relationCartoonAuthor")
@RequiredArgsConstructor
@CheckToken
public class RelationCartoonAuthorController {

    final RelationCartoonAuthorService relationCartoonAuthorService;

    @GetMapping("/list")
    public Result<List<RelationCartoonAuthor>> list() {
        log.info("获取对应列表（漫画-作者）");
        List<RelationCartoonAuthor> list = relationCartoonAuthorService.list();
        return Result.success(list);
    }

    @GetMapping
    public Result<List<RelationCartoonAuthor>> search(
            @RequestParam(required = false) Integer cid,
            @RequestParam(required = false) Integer aid
    ) {
        log.info("获取对应列表（漫画-作者）,cid:{},aid:{}", cid, aid);
        List<RelationCartoonAuthor> list = relationCartoonAuthorService.search(cid, aid);
        return Result.success(list);
    }

    @PostMapping
    public Result<Integer> insert(@RequestBody RelationCartoonAuthor relationCartoonAuthor) {
        log.info("新增对应（漫画-作者）: {}", relationCartoonAuthor);
        Integer id = relationCartoonAuthorService.insert(relationCartoonAuthor);
        return Result.success(id);
    }

    @PutMapping
    public Result<Void> update(@RequestBody RelationCartoonAuthor relationCartoonAuthor) {
        log.info("更新对应（漫画-作者）: {}", relationCartoonAuthor);
        relationCartoonAuthorService.update(relationCartoonAuthor);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result<Void> delete(@PathVariable List<Integer> ids) {
        log.info("删除对应（漫画-作者）: {}", ids);
        relationCartoonAuthorService.delete(ids);
        return Result.success();
    }

}
